<!DOCTYPE html>
{extend name="common/application" /}
{block name="title"}<title>个人中心-实名认证-个人</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/help.css" />
<link rel="stylesheet" type="text/css" href="_CSS_/personal.css"/>

<style type="text/css">
	.hide{display: none !important;}
	.form-group{line-height: 40px;}
	.form-group label{color: #999999;}
	.form-group span{width: 400px;}
	.btns{width: 90px;height: 40px;line-height:40px;text-align:center;
		display: inline-block;font-size: 16px;border:1px solid #E5E5E5;
		border-radius: 5px;float: right;}
	.btns:hover{color: #FFFFFF;}
	.greenBtn{background:#007722;color: #FFFFFF;margin-left: 10px;}
	.redBtn{background: #C75C5C;color: #FFFFFF;}
</style>
{/block}
<!-- 主体内容 -->
{block name="content"}

			<!-- 主体内容 -->
			<div class="main">
				<div class="mainBody normalBox clearfix">
					<!--左菜单-->
					<ul class="menuList fl">
						<li class="showChild">
							<a class="menuItem dropBg" href="personal.html"><span class="icons icon-account"></span>账户管理</a>
							<div class="childMenu">
								<a class="menuchildItem" href="personal.html">个人资料</a>
								<a class="menuchildItem" href="certification.html">实名认证</a>
								<a class="menuchildItem activeMenu" href="account.html">账户安全</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="order.html"><span class="icons icon-order"></span>我的订单</a>
							<div class="childMenu">
								<a class="menuchildItem" href="order.html">我的订单</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="collect_news.html"><span class="icons icon-collection"></span>我的收藏</a>
							<div class="childMenu">
								<a class="menuchildItem" href="collect_news.html">资讯收藏</a>
								<a class="menuchildItem" href="collect_course.html">课程收藏</a>
								<a class="menuchildItem" href="collect_products.html">商品收藏</a>
								<a class="menuchildItem" href="collect_stores.html">店铺收藏</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="address.html"><span class="icons icon-address"></span>地址管理</a>
							<div class="childMenu">
								<a class="menuchildItem" href="address.html">地址管理</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="judge.html"><span class="icons icon-evaluate"></span>评价管理</a>
							<div class="childMenu">
								<a class="menuchildItem" href="judge.html">评价管理</a>
							</div>
						</li>
						<li>
							<a class="menuItem dropBg" href="complain.html"><span class="icons icon-price"></span>申述退款</a>
							<div class="childMenu">
								<a class="menuchildItem" href="complain.html">申述</a>
								<a class="menuchildItem" href="refund_money.html">退款</a>
							</div>
						</li>
						<li class="bb0">
							<a class="menuItem dropBg" href="message.html"><span class="icons icon-news"></span>消息中心</a>
							<div class="childMenu">
								<a class="menuchildItem" href="message.html">消息中心</a>
							</div>
						</li>
					</ul>
					<!--右内容-->
					<div class="menuContent fr">
						<div class="menuConHeader">
							<!--面包屑导航-->
							<div class="breadcrumb">
								<p>当前位置：
									<a href="personal.html">账户管理</a> &gt;
									<a class="curPage" href="javascript:;">账户安全</a>
								</p>
							</div>
						</div>
						<div class="menuConBody">
							<form id="form1" action="" method="post" class='forms dynamic'>
								<div class='form-group pwd'>
									<label>登录密码：</label>
									<span>密码要求6-20位密码，字母、数字、符号至少两种</span>
									<a class="btns greenBtn editPassword" href="javascript:;">修改</a>
								</div>
								<div class='form-group emails'>
									<label>邮箱账号：</label>
									<span></span>
									<a class="btns greenBtn editEmail" href="javascript:;">修改</a>
									<a class="btns redBtn bindEmail hide" href="javascript:;">绑定</a>
								</div>
								<div class='form-group cellphone'>
									<label>手机账号：</label>
									<span/></span>
									<a class="btns greenBtn editPhone" href="javascript:;">修改</a>
									<a class="btns redBtn bindPhone hide" href="javascript:;">绑定</a>
								</div>
								<div class='form-group cefi'>
									<label>实名认证：</label>
									<span>不论是企业还是个人用户，实名认证都能更好的保护账号安全</span>
									<a class="btns redBtn editCefi" href="certification.html">认证</a>
								</div>
								<div class='form-group code'>
									<label>敏感操作：</label>
									<span/>设置后有利于保护您的财产安全</span>
									<a class="btns redBtn editCode" href="javascript:;">设置</a>
								</div>
							</form>	
						</div>
					</div>
				</div>
			</div>
{/block}



{block name="js"}

		<script src="_P_/laydate/laydate.js"></script>
		<script src="_P_/layer/layer.js"></script>

		<script type="text/javascript">
			$(document).ready(function(){
				var userinfo=$.cookie('userinfo');
				if(userinfo) {
					var user_login = $.base64.decode(userinfo).split(",");
					var uid = user_login[0];
					get_user(uid);
					//get_personal(uid);
					/*修改密码*/
					$('.editPassword').on('click', function () {
						layer.open({
							type: 2,
							title: '账户安全',
							fix: false,
							maxmin: true,
							shadeClose: true,
							scrollbar: false,
							area: ['560px', '400px'],
							content: 'edit_pwd.html',
							btn: ['确认', '返回'],
							yes: function (index, layero) {
								var body = layer.getChildFrame('body', index);
								var old_pwd=body.find(".init").val();
								var new_pwd;
								var style=body.find(".pwd").attr('style');
								if(style=='display: inline-block;'||style==undefined){
									new_pwd=body.find(".pwd").val();
								}else{
									new_pwd=body.find(".isHidden").val();
								}
								var copy_pwd=body.find(".cfm").val();
								var res=/^(?=.*[a-zA-Z0-9].*)(?=.*[a-zA-Z\\W].*)(?=.*[0-9\\W].*).{6,16}$/;
								if(!res.test(new_pwd)){
									layer.msg('新密码格式不正确！', {icon: 51});
									return false;
								}
								if(new_pwd!=copy_pwd) {
									layer.msg('新密码2次不一样！', {icon: 51});
									body.find(".cfm").val('');
									return false;
								}
								$.ajax({
									type: "get",
									url: "/index.php/api/account/edit_pwd",
									data:{
										'uid':uid,
										'old_pwd':old_pwd,
										'new_pwd':new_pwd
									},
									dataType: 'jsonp',
									beforeSend: function () {
									var index = layer.load(1, {
										shade: [0.1, '#333333'] //0.1透明度的白色背景
									});
									},
									success: function (msg) {
										layer.closeAll();
										if (msg.code == 200) {
											layer.msg('修改成功！', {icon: 1},function(){
												$.cookie('userinfo',"",{expires:-1,path:'/'}); //清除cookie
												layer.close(index); //如果设定了yes回调，需进行手工关闭
												window.location.href = '/index.php/index/login/index';
											});
										}
										if (msg.code == 1000) {
											layer.msg('修改失败！', {icon: 5});
										}
									}
								});

								//do something

						}
					}
						);
				});
					/*修改邮箱*/
					$('.editEmail').on('click', function(){
						layer.open({
							type: 2,
							title: '账户安全',
							fix: false,
							maxmin: true,
							shadeClose: true,
							scrollbar: false,
							area: ['560px', '400px'],
							content: 'edit_email.html',
							btn: ['确认', '返回'],
							yes: function(index, layero) {
								/*
								 * 邮箱修改成功，给个提示语，然后关闭弹窗
								 */
								var body = layer.getChildFrame('body', index);
								var email=body.find(".init").val();
								var codeNum=body.find(".codeNum").val();
								$.ajax({
									type: "get",
									url: "/index.php/api/account/check_sms",
									data:{
										'message':email,
										'code':codeNum,
										'uid':uid,
										'type':1
									},
									dataType: 'jsonp',
									beforeSend: function () {
									var index = layer.load(1, {
										shade: [0.1, '#333333'] //0.1透明度的白色背景
									});
									},
									success: function (msg) {
										layer.closeAll();
										if (msg.code == 200) {
											layer.msg('绑定成功！', {icon: 1},function(){
												get_user(uid);
												layer.close(index); //如果设定了yes回调，需进行手工关闭
											});
										}
										if (msg.code == 1000) {
											layer.msg('绑定失败！', {icon: 5});
										}
									}
								});
							}
						});
					});
					$('.bindEmail').on('click', function(){
						layer.open({
							type: 2,
							title: '账户安全',
							fix: false,
							maxmin: true,
							shadeClose: true,
							scrollbar: false,
							area: ['560px', '400px'],
							content: 'edit_email.html',
							btn: ['确认', '返回'],
							yes: function(index, layero) {
								var body = layer.getChildFrame('body', index);
								var email=body.find(".init").val();
								var codeNum=body.find(".codeNum").val();
								$.ajax({
									type: "get",
									url: "/index.php/api/account/check_sms",
									data:{
										'message':email,
										'code':codeNum,
										'uid':uid,
										'type':1
									},
									dataType: 'jsonp',
									beforeSend: function () {
									var index = layer.load(1, {
										shade: [0.1, '#333333'] //0.1透明度的白色背景
									});
									},
									success: function (msg) {
										layer.closeAll();
										if (msg.code == 200) {
											layer.msg('绑定成功！', {icon: 1},function(){
												get_user(uid);
												layer.close(index); //如果设定了yes回调，需进行手工关闭
											});
										}
										if (msg.code == 1000) {
											layer.msg('绑定失败！', {icon: 5});
										}
									}
								});
							}
						});
					});
					/*修改手机*/
					$('.editPhone').on('click', function(){
						layer.open({
							type: 2,
							title: '账户安全',
							fix: false,
							maxmin: true,
							shadeClose: true,
							scrollbar: false,
							area: ['560px', '400px'],
							content: 'edit_phone.html',
							btn: ['确认', '返回'],
							yes: function(index, layero) {
								var body = layer.getChildFrame('body', index);
								var email=body.find(".new").val();
								var old_phone=body.find(".init").val();
								var codeNum=body.find(".codeNum").val();
								$.ajax({
									type: "get",
									url: "/index.php/api/account/check_sms",
									data:{
										'message':email,
										'old_phone':old_phone,
										'model':2,
										'code':codeNum,
										'uid':uid,
										'type':2
									},
									dataType: 'jsonp',
									beforeSend: function () {
									var index = layer.load(1, {
										shade: [0.1, '#333333'] //0.1透明度的白色背景
									});
									},
									success: function (msg) {
										layer.closeAll();
										if (msg.code == 200) {
											layer.msg('绑定成功！', {icon: 1},function(){
												get_user(uid);
												layer.close(index); //如果设定了yes回调，需进行手工关闭
											});
										}
										if (msg.code == 1000) {
											layer.msg('绑定失败！', {icon: 5});
										}
									}
								});
							}
						});
					});
					/*修改手机*/
					$('.bindPhone').on('click', function(){
						layer.open({
							type: 2,
							title: '账户安全',
							fix: false,
							maxmin: true,
							shadeClose: true,
							scrollbar: false,
							area: ['560px', '400px'],
							content: 'edit_phone.html?type=2',
							btn: ['确认', '返回'],
							yes: function(index, layero) {
								var body = layer.getChildFrame('body', index);
								var email=body.find(".new").val();
								var old_phone=body.find(".init").val();
								var codeNum=body.find(".codeNum").val();
								$.ajax({
									type: "get",
									url: "/index.php/api/account/check_sms",
									data:{
										'message':email,
										'old_phone':old_phone,
										'model':1,
										'code':codeNum,
										'uid':uid,
										'type':2
									},
									dataType: 'jsonp',
									beforeSend: function () {
									var index = layer.load(1, {
										shade: [0.1, '#333333'] //0.1透明度的白色背景
									});
									},
									success: function (msg) {
										layer.closeAll();
										if (msg.code == 200) {
											layer.msg('绑定成功！', {icon: 1},function(){
												get_user(uid);
												layer.close(index); //如果设定了yes回调，需进行手工关闭
											});
										}
										if (msg.code == 1000) {
											layer.msg('绑定失败！', {icon: 5});
										}
									}
								});
							}
						});
					});
					/*敏感操作密码设置*/
					$('.editCode').on('click', function(){
						layer.open({
							type: 2,
							title: '账户安全',
							fix: false,
							maxmin: true,
							shadeClose: true,
							scrollbar: false,
							area: ['560px', '450px'],
							content: 'edit_code.html',
							btn: ['确认', '返回'],
							yes: function(index, layero) {
								var body = layer.getChildFrame('body', index);
								var username=body.find(".loginName").val();
								var pass=body.find(".password").val();
								var code=body.find(".code").val();
								var cfmcode=body.find(".cfmcode").val();
								if(username==''||code==''||pass==''){
									layer.msg('不能为空！', {icon: 5});
									return false;
								}
								var myreg = /^[a-zA-Z0-9]{6}$/;
								if(!myreg.test(code)){
									layer.msg('密码格式输入不正确！', {icon: 5});
									return false;
								}
								if(code!=cfmcode){
									layer.msg('2次密码不一样！', {icon: 5});
									body.find(".cfmcode").val('');
									return false;
								}
								$.ajax({
									type: "get",
									url: "/index.php/api/account/check_code",
									data:{
										'username':username,
										'password':pass,
										'code':code,
										'cfmcode':cfmcode,
										'uid':uid
									},
									dataType: 'jsonp',
									beforeSend: function () {
									var index = layer.load(1, {
										shade: [0.1, '#333333'] //0.1透明度的白色背景
									});
									},
									success: function (msg) {
										layer.closeAll();
										if (msg.code == 200) {
											layer.msg('绑定成功！', {icon: 1},function(){
												get_user(uid);
												layer.close(index); //如果设定了yes回调，需进行手工关闭
											});
										}else{
											layer.msg(msg.message, {icon: 5});
										}

									}
								});
							}
						}
						);
					});
				}else{
					layer.msg('还未登录！', {icon: 51});
				}

			});
			function get_user(uid){
				$.ajax({
					type: "get",
					url: "/index.php/api/form/user_detail",
					data:{
						'uid':uid
					},
					dataType: 'jsonp',
					success: function (msg) {
						if (msg.code == 200) {
							if(msg.data.email){
								$('.emails').find('span').html('邮箱'+msg.data.email);
								$('.emails').find('.bindEmail').addClass('hide');
								$('.emails').find('.editEmail ').removeClass('hide');
							}else{
								$('.emails').find('span').html('');
								$('.emails').find('.bindEmail').removeClass('hide');
								$('.emails').find('.editEmail ').addClass('hide');
							}
							if(msg.data.phone){
								$('.cellphone').find('span').html('绑定的手机'+msg.data.phone);
								$('.cellphone').find('.bindPhone ').addClass('hide');
								$('.cellphone').find('.editPhone ').removeClass('hide');
							}else{
								$('.cellphone').find('span').html('');
								$('.cellphone').find('.bindPhone ').removeClass('hide');
								$('.cellphone').find('.editPhone ').addClass('hide');
							}
							if(msg.data.code){
								$('.code').find('a').attr('class','btns greenBtn');
								$('.code').find('a').html('已设置');
							}else{
								$('.code').find('a').attr('class','btns redBtn editCode');
								$('.code').find('a').html('设置');
							}
							if(msg.data.authentication==3||msg.data.authentication==4){
								$('.cefi').find('a').attr('class','btns greenBtn');
								$('.cefi').find('a').html('已认证');
							}else{
								$('.cefi').find('a').attr('class','btns redBtn editCode');
								$('.cefi').find('a').html('认证');
							}

						}
						if (msg.code == 1000) {
							layer.msg('网络错误！', {icon: 5});
						}
					}
				});
			}
		</script>
{/block}